﻿CREATE PROCEDURE [dbo].[proc_Orders_Company_Count]
	
	(
		@StartDate nvarchar(50),
		@EndDate nvarchar (50),
		@CompanyId int,
		@MainProjectId int,
		@Stext nvarchar(50)
	)
	
AS

	
	select count(id) from orders 
	where CompanyId=@CompanyId 
         and (Convert(varchar(10),FixtureDate,120)>=@StartDate and Convert(varchar(10),FixtureDate,120)<=@EndDate)
         and (@MainProjectId=0 or MainProjectId=@MainProjectId)
         and ((select e.ename from employee e where e.username=Orders.username) like  '%'+@SText+'%' or isnull((Select CustomerName From Customer Where CustomerId=Orders.CustomerId),'...') like '%'+@SText+'%')  
	RETURN
